<?php
/**
 * @Author Forpastime
 * @Date : 2021/3/25
 * @CreateTime : 10:58 上午
 * @HomePage : http://www.forpastime.com
 */

namespace App\Service;


use Hyperf\Di\Annotation\Inject;

class OrderService implements \App\ServiceInterface\OrderServiceInterface
{
    /**
     *
     * @Inject()
     * @var \App\Model\PatientOrder
    */
    private $patientOrderModel;

    /**
     * @Inject()
     * @var \Hyperf\Redis\Redis
    */
    private $redis;

    /**
     * 微信支付
     * @param $orderSn 订单号
     * @return
    */
    public function wxpay()
    {

    }
    /**
     * @inheritDoc
     */
    public function getOrder(int $orderId)
    {
        return $this->patientOrderModel->getOne($orderId);
    }

    /**
     * 聊天获取订单列表-待处理
     * @param
     * @return
    */
    public function getImOrderList($userId,$type)
    {
        $where = [];
        //如果是客户端
        if($type=='user'){
            $where=['user_id'=>$userId,'paid'=>1,'refund'=>0,'status'=>0];

        }else if($type=='doctor'){//医生端
            $where=['doctor_id'=>$userId,'paid'=>1,'refund'=>0,'status'=>0];

        }
        $orders = $this->patientOrderModel->getOrderList($where);

        return $orders;

    }

    /**
     * 支付成功后修改订单状态
     * @param $orderId int 订单号
     * @return
    */
    public function updateOrderPaid(int $orderId)
    {
        $data=[
            'id'=>$orderId,
            'paid'=>1
        ];
        //将订单状态存入redis缓存
        $this->redis->set();

        return $this->editOrder($orderId,$data);
    }
    /**
     * @inheritDoc
     */
    public function addOrder(array $data)
    {
        return $this->patientOrderModel->saveOne($data);
    }

    /**
     * @inheritDoc
     */
    public function editOrder(int $orderId, array $data)
    {
        return $this->patientOrderModel->saveOne($data);
    }
}